﻿using System;
using System.Collections.Generic;
using System.Text;
using Wangzeran.CodeMaker.Core.Tag;
using Wangzeran.CodeMaker.PlugIns.Util;

namespace Wangzeran.CodeMaker.PlugIns.Tags
{
    /// <summary>
    /// 变量标签
    /// </summary>
    public class VariableTag : TagSupport
    {

        #region Tag Property
        /// <summary>
        /// 变量键
        /// </summary>
        private const string ATTR_KEY = "key";
        /// <summary>
        /// 变量值
        /// </summary>
        private const string ATTR_VALUE = "value";

        #endregion

        /// <summary>
        /// 标签名
        /// </summary>
        public override string TagName
        {
            get { return "c:variable"; }
        }

        /// <summary>
        /// 处理标签
        /// </summary>
        /// <param name="tagStr">标签文本</param>
        /// <param name="value">标签值</param>
        /// <returns></returns>
        public override string ProcessTag(string tagStr, object value)
        {
            try
            {
                if (this.Properties.ContainsKey(ATTR_KEY)
                        && this.Properties.ContainsKey(ATTR_VALUE))
                {
                    VariablesContainer.Variables.Add(
                        this.Properties[ATTR_KEY], this.Properties[ATTR_VALUE]);
                }
                return String.Empty;
            }
            catch (Exception ex)
            {	
                throw ex;
            }
        }
    }
}
